/*
 * Created on Jan 20, 2005
 *
 */
package org.vectrics.security;

import org.vectrics.company.Company;
import org.vectrics.hibernate.ThreadProperties;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.struts.Request;
import org.vectrics.user.Person;

/**
 * @author mmoore
 */
public class PrivilegeUtils {

	public static Person getAuthPerson(Request request) {
		Person authPerson = CoreServiceLocator.getUserAuthService().getAuthorizedPerson(ThreadProperties.getDomain(), request);
		return(authPerson);
	}
	
	public static boolean hasPrivilege(String privilegeCode, Person person) {
		boolean result = CoreServiceLocator.getUserAuthService()
				.hasAccess(privilegeCode, person);
		return(result);
	}

	public static boolean hasRole(String privTypeCode, Long personId, Long companyId) {
		Person person = CoreServiceLocator.getPersonService().findPersonById(personId);
		Company company = CoreServiceLocator.getCompanyService().findCompany(companyId);
		boolean result = person.hasDomainOrGlobalRole(privTypeCode, company.getDomain());
		return(result);
	}
}
